#!/usr/bin/env bash

# NodeOS
#
# Copyright (c) 2013-2017 Jacob Groundwater, Jesús Leganés-Combarro 'piranna'
# and other contributors
#
# MIT License

set -o pipefail


BLD=$(tput bold)
CLR="\e[0m"

GRN="\e[32m"
GRY="\e[90m"
WHT="\e[37m"


CONTEXT=out/latest


cp resources/Dockerfile           $CONTEXT || exit 10
cp resources/Dockerfile-initramfs $CONTEXT || exit 12

cd $CONTEXT || exit 20

ORG=nodeos

docker import barebones.tar.gz $ORG/barebones            || exit 30
docker build -t $ORG/initramfs -f Dockerfile-initramfs . || exit 31

#docker volume create --name $ORG/usersfs        || exit 32
#cat usersfs.tar.gz | docker cp - $ORG/usersfs:/ || exit 33

docker build -t $ORG/nodeos . || exit 34


echo -e "${GRY}-----------------------------------------${CLR}"
echo -e "${GRN}${BLD}Success!${CLR}"
echo -e "${GRN}You just registered a custom NodeOS image${CLR}"
echo -e "${GRY}-----------------------------------------${CLR}"
echo
echo -e "- Interactively run your image with:"

echo -e "${WHT}    npm start${CLR}"
echo
echo -e "- Share your creation with:"
echo -e "${WHT}    docker push $ORG/nodeos${CLR}"
